<?php

namespace App\Jobs;

use App\Modules\Jobs\Services\UpdateSelfRecoAverageService;
use App\Modules\Jobs\Services\UpdateSelfRecoService;
use App\Modules\Jobs\Services\UpdateUserAverageService;
use App\Modules\Jobs\Services\UpdateUserDetailService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class Reward implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $data1;
    protected $data2;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($param1)
    {
        //
        $this->data1 = $param1;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        try{
            $suc_chain = $this->data1;
            UpdateUserDetailService::UpdateUserRewards($suc_chain->begin_uid,$suc_chain->fee);//更新用户打赏次数及金额
            UpdateUserDetailService::updateAverageReward($suc_chain->begin_uid);//更新用户平均打赏
            UpdateUserAverageService::UpdateUserRewardsInfo($suc_chain->fee);
            UpdateSelfRecoService::RecommendSuccessTimes($suc_chain->end_uid);
            UpdateSelfRecoAverageService::RecommendAllSuccessTimes();
        }catch(\Exception $e){
            Log::error('rewardQueue-error:'.$e->getCode().$e->getMessage());
        }
        Log::info("Reward:executed!".json_encode($suc_chain,JSON_UNESCAPED_UNICODE));
    }
}
